<?php include("database_inc.php"); ?>
<?php
error_reporting('IGNORE_REPEATED_ERRORS');
?>
<html>
<HEAD>
<TITLE>
<?php
$start_date = $_GET["start_date"];
$end_date = $_GET["end_date"];
$taxonomy = $_GET["taxonomy"];
echo "$taxonomy between $start_date and $end_date";
?>
</TITLE>
<script language="javascript" type="text/javascript">
function roundNum(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber; // Output the result to the form field (change for your purposes)
}

var state = 'none';

function showhide(layer_ref) { 

if (state == 'block') { 
state = 'none'; 
} 
else { 
state = 'block'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + layer_ref + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[layer_ref].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza = document.getElementById(layer_ref); 
hza.style.display = state; 
} 
} 



	function toggleVisibility(me){
		if (me.style.visibility=="hidden"){
			me.style.visibility="visible";
			}
		else {
			me.style.visibility="hidden";
			}
		}

	function toggleDisplay(me){
		if (me.style.display=="block"){
			me.style.display="inline";
			alert("Text is now 'inline'.");
			}
		else {
			if (me.style.display=="inline"){
				me.style.display="none";
				alert("Text is now 'none'. It will reappear in three seconds.");
				window.setTimeout("blueText.style.display='block';",3000,"JavaScript");
				}
			else {
				me.style.display="block";
				alert("Text is now 'block'.");
				}
			}
		}


</script>
</HEAD>
<body>

<?php




mysql_connect($db_conn_address, $db_conn_username, $db_conn_password) or
    die("Could not connect: " . mysql_error());
mysql_select_db($db_QA_database);


$config = Array();
$result = mysql_query("select Short_Description, Long_Description, Help_URL, Value, Reference_Number from QA.Config");
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
	$config[$row[4]] = $row[3];
}
mysql_free_result($result);




$charturl = "http://chart.apis.google.com/chart?cht=$config[1]&chco=$config[7]&chs=$config[2]x$config[3]&chd=t:";
$largecharturl = "http://chart.apis.google.com/chart?cht=$config[4]&chco=$config[8]&chs=$config[5]x$config[6]&chd=t:";


$start_date = $_GET["start_date"];
$end_date = $_GET["end_date"];
$taxonomy = $_GET["taxonomy"];


///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// NEW SUMMARY REPORT STARTS FOR NEW INPUT DATA
///////////////////////////////////////////////////////////////////////
//Thses are variables which define report appearance and behavior
///////////////////////////////////////////////////////////////////////
$top1 = 3;
$top2 = 5;
$fgcol1 = "#FFFFFF"; 
$fgcol2 = "#000000";
$bgcol1 = "#222222";
$bgcol2 = "#BBBBBB";
$yes_string = "Yes";

///////////////////////////////////////////////////////////////////////
// These are variables calculated during the first half of the report
// and then displayed in the written narrative second half of the report
///////////////////////////////////////////////////////////////////////

//  This is the total number of callers unreachable
$unreachable_callers = 0;

//  This is the total number of callers reached
$reached_callers = 0;



echo "<SPAN style=\"font-family:sans-serif\">";

////////////////////
//REPORT TITLE
////////////////////

echo "<div onclick=\"showhide('draft_div')\"><H3 style=\"text-align:center\">United Way of Metropolitan Atlanta 211<BR>Service Outcome Measurement Report<BR><BR></H3>
<H2 style=\"text-align:center\">Taxonomy: $taxonomy<BR>Start: $start_date <BR>End: $end_date</H2></DIV>";
echo "<HR width=72% style=\"align:center\"><BR>";


////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TOTAL of #XX# INDIVIDUALS CALLED 211; of that number #XX#  follow-up calls were scheduled.
////////////////////////////////////////////////////////////////////////////////////////////////////////////

?>

Total Callers for the period: &nbsp<INPUT type=text id=individuals_called name=individuals_called style="border: 0px; font-family:sans-serif;background: transparent;font-style:bold;font-size:1.25em" onClick="javascript:this.value=prompt('Change value?','')" value="?" readonly size=1/><BR><BR>

Scheduled Followup Calls: &nbsp<INPUT type= text style="border: 0px; font-family:sans-serif;background: transparent;font-style:bold;font-size:1.25em" onClick="javascript:this.value=prompt('Change value?','')" value="?" readonly size=1 id=followup_scheduled name=followup_scheduled /><BR><BR>

<?php


//////////////////////////////////////////////////////////////////////////////////////////////////////
// Got Help & Didn't Get help based on the "Did They Receive Help" Question  stored in QA.Needs.Met
//////////////////////////////////////////////////////////////////////////////////////////////////////
// 1==Yes, 0==No
//////////////////////////////////////////////////////////////////////////////////////////////////////

echo "<TABLE border=0 width=100% align=center><TR><TD valign=top align=center>";

$reached = 0;
$qstring = "select count(QA.Needs.Caller_Reference) as Count FROM QA.Needs, QA.Caller, QA.Taxonomies WHERE QA.Needs.Caller_Reference=QA.Caller.Reference_Number AND QA.Needs.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\"";
$result = mysql_query($qstring);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	$reached = $row[0];
}


$qstring = "select QA.Needs.Met as Met, count(QA.Needs.Caller_Reference) as Count FROM QA.Needs, QA.Caller, QA.Taxonomies WHERE QA.Needs.Caller_Reference=QA.Caller.Reference_Number AND QA.Needs.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.Needs.Met DESC";

$result = mysql_query($qstring);


echo "<TABLE border=0 cellpadding=2px><TR><TH>Did the Caller get help?</TH><TH>Count</TH><TH>%</TH></TR>";
$reasoncharturl = $charturl;
$reasoncharturllarge = $largecharturl;
$reasonchartdata = "";
$reasonchartlabels = "";
$reason_count_total = 0;
$resaon_percent_total = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if($row[0]==1){$description="Yes";}elseif($row[0]==0){$description="No";}else{$description="Error";}
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$description."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$reached)*100)."</TD></TR>";
	$reasonchartdata = $reasonchartdata .",". $row[1];
	$reasonchartlabels = $reasonchartlabels ."|". urlencode($description." (".sprintf("%3.1f",($row[1]/$reached)*100)."%)");
	$reason_count_total = $reason_count_total + $row[1];
	$resaon_percent_total = $resaon_percent_total + (($row[1]/$reached)*100);
}
$reasoncharturl = $reasoncharturl.ltrim($reasonchartdata,",")."&chdl=".ltrim($reasonchartlabels, "|");
$reasoncharturllarge = $reasoncharturllarge.ltrim($reasonchartdata,",")."&chdl=".ltrim($reasonchartlabels, "|");

echo "<TR STYLE=\"color:$fgcol2; background-color:$bgcol2;\"><TD>Total</TD><TD>".$reason_count_total."</TD><TD>".sprintf("%3.0f",$resaon_percent_total)."</TD></TR>";
$unreachable_callers = $reason_count_total;
mysql_free_result($result);
echo "</TABLE></TD><TD>";
echo "<A HREF=\"$reasoncharturllarge\" target=\"_Top\">";
echo "<img src=\"$reasoncharturl\" border=\"0\"></A><BR></TD></TR></TABLE>";



///////////////////////////
//ASSISTANCE RECEIVED GRAPH
///////////////////////////


echo "<TABLE border=0 width=100% align=center><TR><TD valign=top align=center>";

$qstring = "SELECT QA.Assistance.Assistance_Description as Assistance, count(QA.Assistance.Assistance_Description) as Count FROM QA.Assistance, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Assistance.Reference_Number=QA.AgencyFeedback.Assistance AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND NOT(QA.Assistance.Assistance_Description = \"Yes\")  AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY Assistance ASC";
//echo "<BR>$qstring<BR>";
$result = mysql_query($qstring);

echo "<TABLE border=0 cellpadding=2px><TR><TH>Why didn't the caller receive assistance?</TH><TH>Count</TH><TH>%</TH></TR>";
if ($include_needs_in_assistance){ $assistance_count_total = $needs + 0;} else {$assistance_count_total = 0;}
$assistance_percent_total = 0;
$assistancecharturl = $charturl;
$assistancecharturllarge = $largecharturl;
$assistancechartdata = "";
$assistancechartlabels = "";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	$assistance_count_total = $assistance_count_total + $row[1];	
}
$result = mysql_query($qstring);

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
        $value=str_replace("(Explain)", "", $row[0]);
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$value."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$assistance_count_total)*100)."</TD></TR>";
	$assistance_percent_total = $assistance_percent_total + (($row[1]/$assistance_count_total)*100);
	$assistancechartdata = $assistancechartdata .",". $row[1];
	$assistancechartlabels = $assistancechartlabels ."|". urlencode($value." (".sprintf("%3.1f",($row[1]/$assistance_count_total)*100)."%)");
}
echo "<TR STYLE=\"color:$fgcol2; background-color:$bgcol2;\"><TD>Total</TD><TD>".$assistance_count_total."</TD><TD>".sprintf("%3.0f",$assistance_percent_total)."</TD></TR></TABLE>";
echo "</TD><TD>";

$assistancecharturl = $assistancecharturl.ltrim($assistancechartdata,",")."&chdl=".ltrim($assistancechartlabels, "|");
$assistancecharturllarge = $assistancecharturllarge.ltrim($assistancechartdata,",")."&chdl=".ltrim($assistancechartlabels, "|");

mysql_free_result($result);


echo "<A HREF=\"$assistancecharturllarge\" target=\"_Top\">";
echo "<img src=\"$assistancecharturl\" border=\"0\"></A></TR></TD></TABLE>";












































/*

///////////////////////
//Unreachable graph
///////////////////////

echo "<H3>Why were some of the UW211 callers unable to be surveyed?</H3><H4>Taxonomy: $taxonomy<BR>$start_date through $end_date</H4><BR>";

echo "<TABLE border=0 width=100% align=center><TR><TD valign=top align=center>";

$qstring = "select QA.Unreachable_Reasons.Reason_Description as Reason, count(QA.Unreachable.Reason) as Count FROM QA.Unreachable_Reasons, QA.Caller, QA.Unreachable, QA.Taxonomies WHERE QA.Unreachable_Reasons.Reference_Number=QA.Unreachable.Reason AND QA.Unreachable.Caller_Reference=QA.Caller.Reference_Number AND QA.Unreachable.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY REASON ASC";

$result = mysql_query($qstring);


echo "<TABLE border=0 cellpadding=2px><TR><TH>Reason Caller not Surveyed</TH><TH>Count</TH><TH>%</TH></TR>";
$reasoncharturl = $charturl;
$reasoncharturllarge = $largecharturl;
$reasonchartdata = "";
$reasonchartlabels = "";
$reason_count_total = 0;
$resaon_percent_total = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[0]."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$unreach)*100)."</TD></TR>";
	$reasonchartdata = $reasonchartdata .",". $row[1];
	$reasonchartlabels = $reasonchartlabels ."|". urlencode($row[0]." (".sprintf("%3.1f",($row[1]/$unreach)*100)."%)");
	$reason_count_total = $reason_count_total + $row[1];
	$resaon_percent_total = $resaon_percent_total + (($row[1]/$unreach)*100);
}
$reasoncharturl = $reasoncharturl.ltrim($reasonchartdata,",")."&chdl=".ltrim($reasonchartlabels, "|");
$reasoncharturllarge = $reasoncharturllarge.ltrim($reasonchartdata,",")."&chdl=".ltrim($reasonchartlabels, "|");

echo "<TR STYLE=\"color:$fgcol2; background-color:$bgcol2;\"><TD>Total</TD><TD>".$reason_count_total."</TD><TD>".sprintf("%3.0f",$resaon_percent_total)."</TD></TR>";
$unreachable_callers = $reason_count_total;
mysql_free_result($result);
echo "</TABLE></TD><TD>";
echo "<A HREF=\"$reasoncharturllarge\" target=\"_Top\">";
echo "<img src=\"$reasoncharturl\" border=\"0\"></A><BR></TD></TR>";



$qstring = "select QA.Unreachable.Other as Other, COUNT(QA.Unreachable.Other) as Count FROM QA.Unreachable_Reasons, QA.Caller, QA.Unreachable, QA.Taxonomies WHERE QA.Unreachable_Reasons.Reason_Description=\"Other\" AND QA.Unreachable_Reasons.Reference_Number=QA.Unreachable.Reason AND QA.Unreachable.Caller_Reference=QA.Caller.Reference_Number AND QA.Unreachable.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.Unreachable.Other ASC ORDER BY Count DESC LIMIT $top1";
//echo "qstring: $qstring<BR>";

$result = mysql_query($qstring);

echo "<TR><TD colspan=3><BR><H4>Top $top1 <B>Other</B> explanations why caller was unable to be reached</H4>";
echo "<TABLE border=0 cellpadding=2px><TR><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Number of Times</TH><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Explanation</TH></TR>";

$reason_count = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if( strlen($row[0]) > 0) {
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD>".$row[0]."</TD></TR>";
	}else{
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD><span style=\"color=red\">Other selected, but blank entry or no response entered.</span></TD><TD>".$row[1]."</TD></TR>";
	}
	$reason_count += $row[1];
}

mysql_free_result($result);


echo "</TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE><BR>";
echo "<HR width=72% style=\"align:center\"><BR>";


/////////////////////////////
//AGENCY CONTACT RESULT GRAPH
/////////////////////////////


echo "<H3>Did the caller reach someone at the agency?</H3><H4>Taxonomy: $taxonomy<BR>$start_date through $end_date</H4><BR>";

echo "<TABLE border=0 width=100% align=center><TR><TD valign=top align=center>";

$qstring = "SELECT QA.Contacted.Contacted_Description as Contacted, count(QA.Contacted.Contacted_Description) as Count FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.Contacted.Contacted_Description DESC";
//echo "<BR><BR>Qstring: ".$qstring."<BR><BR>";
$result = mysql_query($qstring);


echo "<TABLE border=0 cellpadding=2px><TR><TH>Contact Made with Agency</TH><TH>Count</TH><TH>%</TH></TR>";

$agency_contact_count_total = 0;
$agency_contact_percent_total = 0;
$contactedcharturl = $charturl;
$contactedcharturllarge = $largecharturl;
$contactedchartdata = "";
$contactedchartlabels = "";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[0]."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$agency)*100)."</TD></TR>";
	//echo "<TR><TD>".$row[0]."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$agency)*100)."</TD></TR>";
	$contactedchartdata = $contactedchartdata .",". $row[1];
	$contactedchartlabels = $contactedchartlabels ."|". urlencode($row[0]." (".sprintf("%3.1f",($row[1]/$agency)*100)."%)");
	$agency_contact_count_total = $agency_contact_count_total + $row[1];
	$agency_contact_percent_total = $agency_contact_percent_total + (($row[1]/$agency)*100);
}
//echo "<TR><TD>Total</TD><TD>".$agency_contact_count_total."</TD><TD>".sprintf("%3.0f",$agency_contact_percent_total)."</TD></TR>";
echo "<TR STYLE=\"color:$fgcol2; background-color:$bgcol2;\"><TD>Total*</TD><TD>".$agency_contact_count_total."</TD><TD>".sprintf("%3.0f",$agency_contact_percent_total)."</TD></TR>";
$reached_callers = $agency_contact_count_total;
$contactedcharturl = $contactedcharturl.ltrim($contactedchartdata,",")."&chdl=".ltrim($contactedchartlabels, "|");
$contactedcharturllarge = $contactedcharturllarge.ltrim($contactedchartdata,",")."&chdl=".ltrim($contactedchartlabels, "|");
mysql_free_result($result);
echo "</TABLE></TD><TD>";

echo "<A HREF=\"$contactedcharturllarge\" target=\"_Top\">";
echo "<img src=\"$contactedcharturl\" border=\"0\"></A><BR>";



$qstring = "select QA.AgencyFeedback.Other_Contacted as Other, 
COUNT(QA.AgencyFeedback.Other_Contacted) as Count 
FROM QA.Caller, QA.AgencyFeedback, QA.Taxonomies, QA.Contacted 
WHERE QA.AgencyFeedback.Contacted=QA.Contacted.Reference_Number AND 
QA.Contacted.Contacted_Description=\"Other\" AND 
QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND 
QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND 
QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND 
QA.Caller.Call_Date 
BETWEEN \"".$start_date."\" and \"".$end_date."\" 
GROUP BY QA.AgencyFeedback.Other_Contacted ASC ORDER BY Count DESC LIMIT $top1";

//echo "qstring: $qstring<BR>";

$result = mysql_query($qstring);

echo "<TR><TD colspan=3><BR><H4>Top $top1 <B>Other</B> explanations if caller reached an agency</H4>";
echo "<TABLE border=0 cellpadding=2px><TR><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Number of Times</TH><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Explanation</TH></TR>";

$reason_count = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if( strlen($row[0]) > 0) {
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD>".$row[0]."</TD></TR>";
	}else{
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD><span style=\"color=red\">Other selected, but blank entry or no response entered.</span></TD><TD>".$row[1]."</TD></TR>";
	}
	$reason_count += $row[1];
}

mysql_free_result($result);


echo "</TD></TR></TABLE></TD></TR></TABLE><H6>*This total represents only callers reached who remembered an agency.</H6></TD></TR></TABLE><BR>";

echo "<HR width=72% style=\"align:center\"><BR>";


///////////////////////////
//ASSISTANCE RECEIVED GRAPH
///////////////////////////

/*
echo "<H3>Did the caller receive assistance?</H3><H4>Taxonomy: $taxonomy<BR>$start_date through $end_date</H4><BR>";

$include_needs_in_assistance = 1;

echo "<TABLE border=0 width=100% align=center><TR><TD valign=top align=center>";

$qstring = "SELECT QA.Assistance.Assistance_Description as Assistance, count(QA.Assistance.Assistance_Description) as Count FROM QA.Assistance, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Assistance.Reference_Number=QA.AgencyFeedback.Assistance AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY Assistance ASC";

$result = mysql_query($qstring);

echo "<TABLE border=0 cellpadding=2px><TR><TH>Assistance Received**</TH><TH>Count</TH><TH>%</TH></TR>";
if ($include_needs_in_assistance){ $assistance_count_total = $needs + 0;} else {$assistance_count_total = 0;}
$assistance_percent_total = 0;
$assistancecharturl = $charturl;
$assistancecharturllarge = $largecharturl;
$assistancechartdata = "";
$assistancechartlabels = "";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	$assistance_count_total = $assistance_count_total + $row[1];	
}
$result = mysql_query($qstring);
if ($include_needs_in_assistance){

        if($needs_values[0]>0)
	{	$assistancechartdata = $assistancechartdata .",". $needs_values[0];
		$assistancechartlabels = $assistancechartlabels ."|". urlencode($needs_labels[0]." (".sprintf("%3.1f",($needs_values[0]/$assistance_count_total)*100)."%)");
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$needs_labels[0]."</TD><TD>".$needs_values[0]."</TD><TD>".sprintf("%3.1f",($needs_values[0]/$assistance_count_total)*100)."</TD></TR>";
		$assistance_percent_total = $assistance_percent_total + (($needs_values[0]/$assistance_count_total)*100);
	}

	if($needs_values[1]>0){
		$assistancechartdata = $assistancechartdata .",". $needs_values[1];
		$assistancechartlabels = $assistancechartlabels ."|". urlencode($needs_labels[1]." (".sprintf("%3.1f",($needs_values[1]/$assistance_count_total)*100)."%)");
	        echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$needs_labels[1]."</TD><TD>".$needs_values[1]."</TD><TD>".sprintf("%3.1f",($needs_values[1]/$assistance_count_total)*100)."</TD></TR>";
		$assistance_percent_total = $assistance_percent_total + (($needs_values[1]/$assistance_count_total)*100);
	}        
	$reached_callers = $reached_callers+$needs_values[0]+$needs_values[1];

}
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[0]."</TD><TD>".$row[1]."</TD><TD>".sprintf("%3.1f",($row[1]/$assistance_count_total)*100)."</TD></TR>";
	$assistance_percent_total = $assistance_percent_total + (($row[1]/$assistance_count_total)*100);
	$assistancechartdata = $assistancechartdata .",". $row[1];
	$assistancechartlabels = $assistancechartlabels ."|". urlencode($row[0]." (".sprintf("%3.1f",($row[1]/$assistance_count_total)*100)."%)");
}
echo "<TR STYLE=\"color:$fgcol2; background-color:$bgcol2;\"><TD>Total***</TD><TD>".$assistance_count_total."</TD><TD>".sprintf("%3.0f",$assistance_percent_total)."</TD></TR></TABLE>";
echo "</TD><TD>";

$assistancecharturl = $assistancecharturl.ltrim($assistancechartdata,",")."&chdl=".ltrim($assistancechartlabels, "|");
$assistancecharturllarge = $assistancecharturllarge.ltrim($assistancechartdata,",")."&chdl=".ltrim($assistancechartlabels, "|");

mysql_free_result($result);


echo "<A HREF=\"$assistancecharturllarge\" target=\"_Top\">";
echo "<img src=\"$assistancecharturl\" border=\"0\"></A>";










$qstring = "SELECT QA.AgencyFeedback.Explanation as Explanation, COUNT(QA.AgencyFeedback.Explanation) as Count FROM QA.Caller, QA.AgencyFeedback, QA.Taxonomies, QA.Assistance WHERE QA.Assistance.Reference_Number = QA.AgencyFeedback.Assistance AND QA.Assistance.Assistance_Description like \"Other\" AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.AgencyFeedback.Explanation ASC ORDER BY Count DESC LIMIT $top1";

//echo "qstring: $qstring<BR>";

$result = mysql_query($qstring);

echo "<TR><TD colspan=3><BR><H4><A name=\"other_assistance\">Top $top1 <B>Other</B> reasons assistance not received when caller reached an agency</A></H4>";
echo "<TABLE border=0 cellpadding=2px><TR><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Count</TH><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Explanation</TH></TR>";

$reason_count = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if( strlen($row[0]) > 0) {
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD>".$row[0]."</TD></TR>";
	}else{
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD><span style=\"color=red\">Other selected, but blank entry or no response entered.</span></TD><TD>".$row[1]."</TD></TR>";
	}
	$reason_count += $row[1];
}

mysql_free_result($result);


echo "</TD></TR></TABLE></TD></TR></TABLE><TR colspan=3><TD>These items apply only to the item in the list marked \"Other\"</TD></TR></TABLE><BR>";
echo "<BR>";

*/
//////////////////////////////////////////////////////
// TOP EXPLANATION REASONS FOR NOT RECEIVING ASSISTANCE
//////////////////////////////////////////////////////
/*
$qstring = "SELECT QA.AgencyFeedback.Explanation as Explanation, COUNT(QA.AgencyFeedback.Explanation) as Count FROM QA.Caller, QA.AgencyFeedback, QA.Taxonomies, QA.Assistance WHERE QA.Assistance.Reference_Number = QA.AgencyFeedback.Assistance AND QA.Assistance.Assistance_Description like \"%(Explain)%\" AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.AgencyFeedback.Explanation ASC ORDER BY Count DESC LIMIT $top1";

//echo "qstring: $qstring<BR>";

$result = mysql_query($qstring);

echo "<H4>Top $top1 additional <B>Explanations<B> given for not receiving assistance</H4>";
echo "<TABLE border=0 cellpadding=2px><TR><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Count</TH><TH STYLE=\"color:$fgcol2; background-color:$bgcol2;\">Explanation</TH></TR>";

$reason_count = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if( strlen($row[0]) > 0) {
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD>".$row[0]."</TD></TR>";
	}else{
		echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD><span style=\"color=red\">Explanation requested but none provided.</span></TD></TR>";
	}
	$reason_count += $row[1];
}

mysql_free_result($result);


echo "</TD></TR><TR><TD colspan=3>These only apply to those items marked with \"(Explain)\" in the above list</TD></TR></TABLE><BR>";
echo "<H6>** Need Met/Unmet indicates the caller was unable to identify the agency when asked. All other callers provided the name of the agency.<BR>
      *** This total represents both callers who knew an agency and those who did not.</H6><BR>";
echo "<HR width=72% style=\"align:center\"><BR>";




*/

//////////////////////////////////////////////////////
// TOP AGENCIES REFERRED TO
//////////////////////////////////////////////////////

/*
echo "<H3>The top $top2 agencies referred to:</H3><H4>Taxonomy: $taxonomy<BR>$start_date through $end_date</H4><BR>";



$qstring = "select QA.Agencies.Agency_Description, count(QA.Agencies.Agency_Description) as Count ";
$qstring = $qstring."FROM QA.Agencies, QA.Taxonomies, QA.Caller, QA.AgencyFeedback  ";
$qstring = $qstring."WHERE QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Agencies.Reference_Number=QA.AgencyFeedback.Agency AND QA.Taxonomies.Reference_Number=QA.AgencyFeedback.Taxonomy AND QA.Caller.Reference_Number=QA.AgencyFeedback.Caller_Reference AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" AND \"".$end_date."\"";
$qstring = $qstring."GROUP BY QA.Agencies.Agency_Description Order BY Count DESC LIMIT $top2";
$result = mysql_query($qstring);


echo "<TABLE border=0 cellpadding=2px><TR><TH>Count</TH><TH>Agency Name</TH></TR>";

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	echo "<TR STYLE=\"color:$fgcol1; background-color:$bgcol1;\"><TD>".$row[1]."</TD><TD>".$row[0]."</TD></TR>";
}

mysql_free_result($result);

echo "</TABLE>";


echo "<HR width=90% style=\"align:center\"><BR>";

*/
//////////////////////////////////////////////////////
//PAGE 2
//////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TOTAL of #XX# INDIVIDUALS CALLED 211; of that number #XX#  follow-up calls were scheduled.
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
echo "<H3>$taxonomy</H3><BR>"; 
*/
?>
<!--
A total of &nbsp<INPUT type=text id=individuals_called name=individuals_called style="border: 0px; font-family:sans-serif;background: transparent;font-style:bold;font-size:1.25em" onClick="javascript:this.value=prompt('Change value?','')" value="?" readonly size=1/>individuals called 211;
of that number &nbsp<INPUT type= text style="border: 0px; font-family:sans-serif;background: transparent;font-style:bold;font-size:1.25em" onClick="javascript:this.value=prompt('Change value?','')" value="?" readonly size=1 id=followup_scheduled name=followup_scheduled />follow-up calls were scheduled.<BR><BR>
-->
<?php

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CONTACT WAS ATTEMPTED WITH #[TotalCallerRecordsInTimePeriod] callers and of that number:
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*************two caller calculation block**********************/
/*
$contacted_results = array();
$two_call_unique = 0;
foreach($two_calls as $key => $value){
	$continue=2;
	$qstring = "SELECT QA.Contacted.Contacted_Description as Contacted FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Caller.Reference_Number=$value AND QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\"";
	$result = mysql_query($qstring);
	while (($row = mysql_fetch_array($result, MYSQL_BOTH))&&($continue>0)) {
		if($row[0]==$yes_string){
			if($contacted_results[$row[0]] == null){$contacted_results[$row[0]]=0;}
			$contacted_results[$row[0]]=$contacted_results[$row[0]]+1;
			$two_call_unique++;
			$continue = 0;
		}elseif($continue==2){
			$continue = $continue - 1;
		}else{
			if($contacted_results[$row[0]] == null){$contacted_results[$row[0]]=0;}
			$contacted_results[$row[0]]=$contacted_results[$row[0]]+1;			
			$two_call_unique++;
			$continue = $continue - 1;
		}
	}
	mysql_free_result($result);
}	
$twocallresults = $contacted_results;
$onecontacted_results = array();
foreach($one_call as $key=>$value){
	$qstring = "SELECT QA.Contacted.Contacted_Description as Contacted, count(QA.Contacted.Contacted_Description) as Count FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Caller.Reference_Number=$value AND QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.Contacted.Contacted_Description DESC";
	$result = mysql_query($qstring);
	while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
		if($onecontacted_results[$row[0]] == null){$onecontacted_results[$row[0]]=0;}
		$onecontacted_results[$row[0]]=$onecontacted_results[$row[0]]+1;
	}
	mysql_free_result($result);
}
$onecallresults = $onecontacted_results;
$total_callers = count($one_call)+$two_call_unique;
*/
/*************two caller calculation block**********************/

?>
<!--
Contact was attempted with <span style="font-family:sans-serif;background: transparent;font-style:bold;font-size:1.25em"><?php echo ($unreachable_callers + $total_callers+($needs_values[0]+$needs_values[1])); ?></SPAN>^ callers and of that number:<BR><BR>
-->
<?php

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#[UnreachableInTimePeriod] (#%){[UnreachableInTimePeriod]/[TotalCallerRecordsInTimePeriod]} were unreachable (after 3 attempts)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

?>


<?php 
/*
echo "$unreachable_callers ("; 
$temppercent = 100*($unreachable_callers/($unreachable_callers + $reached_callers));
echo sprintf("%3.0f",$temppercent)."%)";
*/
?>
<!--were unreachable (after 3 attempts)<BR><BR>-->
<?php
///////////////////////////
//TABLE OF UNREACHABLE
///////////////////////////
?>
<!--
<UL>
-->
<?php
/*
$qstring = "select QA.Unreachable_Reasons.Reason_Description as Reason, count(QA.Unreachable.Reason) as Count FROM QA.Unreachable_Reasons, QA.Caller, QA.Unreachable, QA.Taxonomies WHERE QA.Unreachable_Reasons.Reference_Number=QA.Unreachable.Reason AND QA.Unreachable.Caller_Reference=QA.Caller.Reference_Number AND QA.Unreachable.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY REASON ASC";
$result = mysql_query($qstring);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	echo "<LI>$row[1](".sprintf("%3.1f",($row[1]/$unreachable_callers)*100)."%) $row[0]</LI>";
}
mysql_free_result($result);
*/
?>
<!--
</UL><BR><BR>
-->
<?php
/////////////////////////////////////////////////////////////////////////////////
//# (#%) callers were surveyed (exceeding goal of #[ContactedGoal]% contact)
/////////////////////////////////////////////////////////////////////////////////
/*

$reached_callers = $total_callers + ($needs_values[0]+$needs_values[1]);
echo $reached_callers;
*/
?> 
<!--
callers were surveyed <DIV id="goalmet" name="goalmet">(exceeded goal of 3% contact)</DIV>
<UL>
<LI><?php echo ($needs_values[0]+$needs_values[1]); ?> didn't remember the agency</LI>
<UL>
  <LI><?php echo "$needs_values[0] (".sprintf("%3.1f",($needs_values[0]/($needs_values[0]+$needs_values[1]))*100)."%)"; ?> were unable to meet their need</LI>
  <LI><?php echo "$needs_values[1] (". sprintf("%3.1f",($needs_values[1]/($needs_values[0]+$needs_values[1]))*100)."%)"; ?> were able to meet their need</LI>
</UL>
-->


<?php 
/////////////////////////////////////////////////////////////////////////////////
//TABLE OF AGENCY CONTACTED//////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*



$contacted_results = array();
$two_call_unique = 0;
foreach($two_calls as $key => $value){
	$continue=2;
	$qstring = "SELECT QA.Contacted.Contacted_Description as Contacted FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Caller.Reference_Number=$value AND QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\"";
	$result = mysql_query($qstring);
	while (($row = mysql_fetch_array($result, MYSQL_BOTH))&&($continue>0)) {
		if($row[0]==$yes_string){
			if($contacted_results[$row[0]] == null){$contacted_results[$row[0]]=0;}
			$contacted_results[$row[0]]=$contacted_results[$row[0]]+1;
			$two_call_unique++;
			$continue = 0;
		}elseif($continue==2){
			$continue = $continue - 1;
		}else{
			if($contacted_results[$row[0]] == null){$contacted_results[$row[0]]=0;}
			$contacted_results[$row[0]]=$contacted_results[$row[0]]+1;			
			$two_call_unique++;
			$continue = $continue - 1;
		}
	}
	mysql_free_result($result);
}	
$twocallresults = $contacted_results;

$onecontacted_results = array();
foreach($one_call as $key=>$value){
	$qstring = "SELECT QA.Contacted.Contacted_Description as Contacted, count(QA.Contacted.Contacted_Description) as Count FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies WHERE QA.Caller.Reference_Number=$value AND QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" GROUP BY QA.Contacted.Contacted_Description DESC";
	$result = mysql_query($qstring);
	while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
		if($onecontacted_results[$row[0]] == null){$onecontacted_results[$row[0]]=0;}
		$onecontacted_results[$row[0]]=$onecontacted_results[$row[0]]+1;
	}
	mysql_free_result($result);
}


$onecallresults = $onecontacted_results;
$total_callers = count($one_call)+$two_call_unique;
*/
?>
<!--
<LI>--><?php /*echo $total_callers;*/ ?> 
<!--remembered the agency when asked if they called the agency and reached someone the callers responded:</LI>
<OL>
<LI>--><?php /*echo count($one_call);*/ ?> 
<!--
of the callers provided feedback on one agency</LI>
<UL>
-->
<?php
/*
$total_callers = count($one_call);
foreach($onecallresults as $outcome_description=>$outcome_count){
	echo "<LI> $outcome_count (";
        printf("%3.1f",(($outcome_count/$total_callers)*100));
	echo "%) $outcome_description</LI>";
}
*/
?>
<!--
</UL>
<LI>
-->
<?php /*echo count($two_calls); */?> 
<!--
of the callers provided feedback on two agencies (outcomes are biased for positive feedback)</LI>
<UL>
-->
<?php
/*
$two_call_unique = count($two_calls);
foreach($twocallresults as $outcome_description=>$outcome_count){
	echo "<LI> $outcome_count (";
        printf("%3.1f",(($outcome_count/$two_call_unique)*100));
	echo "%) $outcome_description</LI>";
}
*/
?>
<!--
</UL>

<LI>The combined outcomes biased for positive outcomes</LI>
<UL>
-->
<?php
/*
$total_callers = count($one_call)+$two_call_unique;

$myArray = array();
$myarray[0] = $onecallresults;
$myarray[1] = $twocallresults ;
$joint_results=array();
foreach($myarray as $value)
{
  foreach($value as $key=>$secondValue)
   {
       if(!isset($joint_results[$key]))
        {
           $joint_results[$key]=0;
        }
       $joint_results[$key]+=$secondValue;
   }
}

foreach($joint_results as $outcome_description=>$outcome_count){
	echo "<LI> $outcome_count (";
        printf("%3.1f",(($outcome_count/$total_callers)*100));
	echo "%) $outcome_description</LI>";
}
*/
?>
<!--
</UL>
</UL>
</UL>
<BR>
Of the <?php echo $joint_results[$yes_string]; ?>:<BR>
<UL>
-->
<?php
//////////////////////////////////////////////////////
//Out of the # callers:
// #(#%) Received assistance
// #(#%) Assistance rejected
// #(#%) Service temporarily unavailable
//////////////////////////////////////////////////////
/*
$qstring = "SELECT
 QA.Assistance.Assistance_Description as Assistance, QA.Caller.Reference_Number as Caller
FROM QA.Contacted, QA.Caller, QA.AgencyFeedback, QA.Taxonomies, QA.Assistance  
WHERE QA.Assistance.Reference_Number=QA.AgencyFeedback.Assistance AND QA.Contacted.Contacted_Description like \"$yes_string\" AND 
QA.Contacted.Reference_Number=QA.AgencyFeedback.Contacted AND QA.AgencyFeedback.Caller_Reference=QA.Caller.Reference_Number AND QA.AgencyFeedback.Taxonomy=QA.Taxonomies.Reference_Number AND QA.Taxonomies.Taxonomy_Description = \"".$taxonomy."\" AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" and \"".$end_date."\" ";
$result = mysql_query($qstring);
//echo "qstring: $qstring<BR>";
$lastrow = array();
$deduped_outcome_count = 0;
$deduped_output = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if($lastrow[1] != $row [1]){
		$deduped_outcome_count++;
		if(is_null($deduped_output[$row[0]])){
			$deduped_output[$row[0]] = 1;
		}else{
			$deduped_output[$row[0]]++;
		}
		$lastrow = $row;
	}else{
		$lastrow = $row;
		//echo "deduped<BR>";
	}
}
mysql_free_result($result);
//print_r($deduped_output);
//echo "<BR>deduped_outcome_count: $deduped_outcome_count<BR>";

foreach($deduped_output as $outcome_description=>$outcome_count){
	if($outcome_description=="Other"){
		echo "<LI><A HREF=\"#other_assistance\"> $outcome_count (";
        	printf("%3.1f",(($outcome_count/$deduped_outcome_count)*100));
		echo "%) $outcome_description</A></LI>";
	}else{
		echo "<LI> $outcome_count (";
        	printf("%3.1f",(($outcome_count/$deduped_outcome_count)*100));
		echo "%) $outcome_description</LI>";
	}
}
*/
?>
<!--
</UL>
<BR><BR>
<HR width=90% style="align:center"><BR>
<H6>^This number represents the total callers which is unreachables, needs met, needs unmet, and callers reached.  Due to callers being allowed to provide more than one agency feedback be careful of double counting when reviewing this report.</H6>
-->
</SPAN>
<HR width=100% style="align:center"><CENTER><span style="font-size:0.72em">Report generated <?php echo date('l jS \of F Y h:i:s A'); ?></SPAN></CENTER>
</BODY></HTML>